package edu.ncu.service.impl;

import edu.ncu.dao.GreatDao;
import edu.ncu.service.GreatService;
import edu.ncu.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 点赞服务
 * 首先将点赞存储在redis上面，当点赞的
 */
@Service("greatService")
public class GreatServiceImpl implements GreatService {
    @Autowired
    private GreatDao greatDao ;

    /**
     * 点赞动态
     * @param publishId
     * @param userId
     * @return
     */
    @Override
    public boolean GreatToPublish(int publishId, int userId) {
        // 点赞表中插入数据
        if (greatDao.insertGreatOfPublish(publishId,userId) ) {
            // 对应的动态点赞数+1
            greatDao.setGreatOfPublish(publishId) ;
            return true ;
        }
        return false;
    }

    /**
     * 点赞照片
     * @param photoId
     * @param userId
     * @return
     */
    @Override
    public boolean GreatToPhoto(int photoId, int userId) {
        if (greatDao.insertGreatOfPhoto(photoId,userId)) {
            greatDao.setGreatOfPhoto(photoId) ;
            return true ;
        }
        return false;
    }

    /**
     * 点赞评论
     * @param commentId
     * @param userId
     * @return
     */
    @Override
    public boolean GreatToComment(int commentId, int userId) {
        if (greatDao.insertGreatOfComment(commentId,userId)) {
            greatDao.setGreatOfComment(commentId) ;
            return true ;
        }
        return false;
    }
}
